#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int T,n,m,L,V,ans1,ans2,d[100009],v[100009],a[100009],p[100009],sum[100009];
string chao[100009];
bool vis[100009];
bool cmp(int a,int b){
    return a>b;
}
int q[100009];
int main(){
    IOS
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        ans1=0,ans2=0;
        memset(vis,0,sizeof(vis));
        memset(sum,0,sizeof(sum));
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;++i)
            cin>>d[i]>>v[i]>>a[i],chao[i].clear();
        for(int i=1;i<=m;++i)
            cin>>p[i];
        for(int i=1;i<=n;++i){
            if(v[i]>V&&a[i]>=0){
                bool h=0;
                for(int j=1;j<=m;++j){
                    if(p[j]>=d[i])
                        h=1,chao[i]+=j+'0';
                }
                if(h)
                    ans1++;
            }
            else if(a[i]<=0&&v[i]<=V);
            else{
                double nv;
                bool h=0;
                for(int j=1;j<=m;++j){
                    if(p[j]>=d[i]){
                        nv=sqrt(v[i]*v[i]+2*a[i]*(p[j]-d[i]));
                        if(nv>V)
                            h=1,chao[i]+=j+'0';
                    }
                }
                if(h)
                    ans1++;
            }
        }





        for(int i=1;i<=m;++i){
            bool h=1;
            for(int j=1;j<=n;++j){
                int siz=0;
                for(int k=1;k<chao[j].size();++k){
                    if(vis[chao[j][k]-'0']!=1&&chao[j][k]-'0'==i)
                        siz++;
                }
                if(siz==1){
                    h=0;
                    break;
                }
            }
            if(h)
                vis[i]=1;
            ans2+=vis[i];
        }

        cout<<ans1<<' '<<m-ans2<<endl;
    }
    return 0;
}
